<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      //   axios().then().catch()

      // axios的原理：Promise+xhr
      function myAxios() {
        return new Promise((resolve, reject) => {
          // 发起请求（xhr）
          const xhr = new XMLHttpRequest()
          xhr.open('get', 'http://ajax-api.itheima.net/api/news')
          xhr.addEventListener('load', function () {
            // console.log(xhr.response)
            resolve(xhr.response)
          })
          xhr.send()
        })
      }
      myAxios().then((res) => {
        console.log(res)
      })
    </script>
  </body>
</html>
